import { _decorator, Component, instantiate, Node, Prefab, Vec3 } from 'cc';
import { heiziControl } from './heiziControl';
const { ccclass, property } = _decorator;

@ccclass('heiziManager')
export class heiziManager extends Component {

  @property(Prefab)
  heiziPre: Prefab = null
  isCreateHeizi: boolean = true

  start() {
    this.schedule(() => {
      this.createHeizi(Math.random() * 10 > 5)
    }, 2)
  }

  update(deltaTime: number) {

  }
  createHeizi(dir: boolean) {
    if (!this.isCreateHeizi) return
    const heizi = instantiate(this.heiziPre)
    heizi.getComponent(heiziControl).direction = dir
    const { x, y, z } = this.node.position
    heizi.setPosition(new Vec3(!dir ? x : 100, y, z))
    this.node.getParent().addChild(heizi)
  }
}


